package com.itheima.capsulation;

public class capStudent {
    String name;
    //1.如何隐藏:用private关键字修饰成员变量,就只能在本类中被直接访问,其他任何地方不能直接访问(如.name)
    private int age;
    private double chinese;
    private double math;

    //2.如何暴露(合理暴露),使用publici修饰的get和set方法合理暴露
    //成员变量的取值和赋值
    public void setAge(int age){      //为年龄赋值
        if(age>0 && age<200){
            this.age=age;
        }else{
            System.out.println("您赋值的年龄数据非法");
        }
    }

    public int getAge(){    //为年龄赋值
        return age;
    }

    //语文,数学成绩也需要同样的操作

    public void printAllscore(){
        System.out.println(name + "的总成绩是" + (chinese + math));
    }

    public void printAverageScore(){
        System.out.println(name + "的平均成绩是" + (chinese + math) / 2);
    }

}
